package com.linghu.qqservice.service;

import java.util.HashMap;
import java.util.Iterator;

/**
 * @author 令狐荣豪
 * @version 1.0
 * 该类用于管理和客户端通信的线程
 */
public class ManagerClientThreads {
    private static HashMap<String ,ServerConnectClientThread> hm=new HashMap<>();

    public static HashMap<String,ServerConnectClientThread> getHm(){
        return hm;//返回hm
    }

    //把线程对象添加到hm集合中
    public static void addClientThread(String userId,ServerConnectClientThread serverConnectClientThread){
        hm.put(userId,serverConnectClientThread);
    }

    //从集合中删除移除某个线程对象
    public static void removeServerConnectClientThread(String userId){
        hm.remove(userId);
    }

    //根据userID返回ServerConnectClientThread线程
    public static ServerConnectClientThread geterverConnectClientThread(String userID){
        return hm.get(userID);
    }

    //这里编写方法，可以返回在线用户列表
    public  static String getOnlineUser(){
        //遍历集合，遍历hashmap的key
        Iterator<String> iterator = hm.keySet().iterator();
        String onlineUserList="";
        while (iterator.hasNext()) {
            onlineUserList +=  iterator.next().toString()+" ";
        }
        return onlineUserList;
    }
}
